<template>
  <div>
    <h2>物流相关信息</h2>
    <div class="logistics-info-header">
      <div class="logistics-info-header-left">
        <div
          class="logistics-status blue"
          v-logisticsStatus="orderInfo.logisticsStatus"
        ></div>
        <div class="logistics-company">{{ orderInfo.logisticsCompany }}</div>
        <div class="logistics-no">{{ orderInfo.logisticsNo }}</div>
      </div>
    </div>
    <ul class="logistics-info-list" v-show="close">
      <li v-for="(item, index) in orderInfo.logisticsInfo" :key="index">
        <div class="logistics-info-list-time">{{ item.time }}</div>
        <div class="logistics-info-list-content">{{ item.content }}</div>
      </li>
    </ul>
    <button @click="wulu" v-role="orderInfo.role">查看物流详情</button>
  </div>
</template>

<script>
export default {
  name: "OrderInfo",
  props: {
    orderInfo: Object,
  },
  data(){
    return {
      close:false
    }
  },
  directives: {
    // 自定义一个局部指令
    logisticsStatus: {
      inserted(el, binding) {
        switch (binding.value) {
          case 0:
            {
              el.style.color = "red";
              el.innerText = "未发货";
            }
            break;
          case 1:
            {
              el.style.color = "bule";
              el.innerText = "已发货";
            }
            break;
          case 2:
            {
              el.style.color = "#087";
              el.innerText = "已签收";
            }
            break;
          case 3:
            {
              el.style.color = "pelper";
              el.innerText = "未签收";
            }
            break;
        }
      },
    },
    role:{
      inserted(el, binding){
        if(binding.value !== 'zhangsan' || 'lisi' || 'admin'){
          // el.parentNode.removeChild(el)
          console.log(1);
        }
      }
    }
  },
  methods:{
    wulu(){
      this.close=!this.close
    }
  }
};
</script>
<style scoped lang="less">
.logistics-info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.logistics-info-header-left {
  display: flex;
  align-items: center;
}

.logistics-status {
  font-weight: bold;
  font-size: 16px;
  color: #007bff;
}

.logistics-company,
.logistics-no {
  margin-left: 10px;
  font-size: 14px;
  color: #333;
}

.logistics-info-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 230px;
  overflow-y: auto;
}

.logistics-info-list li {
  display: flex;
  margin-bottom: 10px;
}

.logistics-info-list-time {
  font-size: 12px;
  color: #999;
  width: 80px;
  text-align: right;
  margin-right: 10px;
}

.logistics-info-list-content {
  font-size: 14px;
  color: #333;
}
</style>
